﻿
using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.WebApp;
using Gift.Model;
using Gift.Utile;
using System.IO;

namespace WebApp.admin.warehouse
{
    public partial class warehouse : BaseAdmin
    {

  
        tbWarehouse oWarehous;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindWarehouse();
             
            }
        }

        void BindWarehouse()
        {
            if (Request.QueryString["ot"] == "ed")
            {
                oWarehous = BaseFactory.theWarehouse.GetModel(int.Parse(Request.QueryString["id"]));
                this.txtWareName.Text = oWarehous.warehouseName;
                this.txtbh.Text = oWarehous.warebh;
                this.txtPhone.Text = oWarehous.phone;
                this.txtAddress.Text = oWarehous.address;
                this.txtName.Text = oWarehous.warehouseMan;
                this.txtContent.Text = oWarehous.content;
                
            }
        }




        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            if (Request.QueryString["ot"] == "ed")
            {
                oWarehous = BaseFactory.theWarehouse.GetModel(int.Parse(Request.QueryString["id"]));
                oWarehous.warehouseName = this.txtWareName.Text;
                oWarehous.warebh = this.txtbh.Text  ;
                 oWarehous.phone = this.txtPhone.Text;
                oWarehous.address = this.txtAddress.Text;
                 oWarehous.warehouseMan = this.txtName.Text ;
                oWarehous.content = this.txtContent.Text  ;

                if (BaseFactory.theWarehouse.Update(oWarehous))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");window.location.href='warehouseList.aspx';</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
                Response.Write("<script> alert('修改成功!');window.location.href='warehouseList.aspx';</script>");
            }
            else
            {
                oWarehous = new tbWarehouse();
                oWarehous.warehouseName = this.txtWareName.Text;
                oWarehous.warebh = this.txtbh.Text;
                oWarehous.phone = this.txtPhone.Text;
                oWarehous.address = this.txtAddress.Text;
                oWarehous.warehouseMan = this.txtName.Text;
                oWarehous.content = this.txtContent.Text;
                oWarehous.companyId = int.Parse(base.Administrator.CompanyId);
                oWarehous.createTime = DateTime.Now;
                oWarehous.creater = int.Parse(base.Administrator.AdminUserId);

                BaseFactory.theWarehouse.Add(oWarehous);
                Response.Write("<script> alert('添加成功!');window.location.href='warehouseList.aspx';</script>");
            }


        }


    }
}
    
